import { CustomErrorCode, CustomSuccessCode } from './enums'

// 自定义code类型
type CustomResponseCode = CustomErrorCode | CustomSuccessCode

// 后端返回的 response.json() 结果数据格式
interface BaseResponseData<
  Data,
  Message extends string,
  Code extends CustomResponseCode = CustomSuccessCode.OK
> {
  code: Code
  message: Message
  data: Data
}

// 后端返回的请求成功 response.json() 数据格式
type SuccessResponseData<Data, Message extends string> = BaseResponseData<
  Data,
  Message,
  CustomSuccessCode.OK
>

// 后端返回的请求失败 response.json() 数据格式
type ErrorResponseData<
  Data,
  Message extends string,
  Code extends CustomErrorCode = CustomErrorCode.BAD_REQUEST
> = BaseResponseData<Data, Message, Code>

export type { BaseResponseData, SuccessResponseData, ErrorResponseData }
